package com.tiny_wind.tiny_wind_diary.utility;

import java.text.SimpleDateFormat;
import java.util.Date;

public class GaTimeManager {
	public static SimpleDateFormat mssdf;
	public static SimpleDateFormat mssdf_min;
	public static GaTimeManager sharedInstance = new GaTimeManager();
	static {
		mssdf = new SimpleDateFormat();
		mssdf.applyPattern("yyyy-MM-dd HH:mm:ss");
		mssdf_min = new SimpleDateFormat();
		mssdf_min.applyPattern("yyyyMMddHHmmss");
	}

	// yyyy-MM-dd HH:mm:ss 19位的字符串.
	public String stdDateTimeStringForNow() {
		Date d_now = new Date();
		return mssdf.format(d_now);
	}

	public String minTimeStringForNow() {
		Date d_now = new Date();
		return mssdf_min.format(d_now);
	}

	// 获取东8区的今天0点的标准时间字符串,究竟是Date创建的是当前时区的date??
	public String stdTimeStringForTodayZero() {
		Date d_now = new Date();
		// 每天的毫秒数
		long l = 24 * 60 * 60 * 1000;
		long l_toayZero = d_now.getTime() - d_now.getTime() % l - 8 * 60 * 60 * 1000;
		Date d_todayZero = new Date(l_toayZero);
		return mssdf.format(d_todayZero);
	}

	// 获取东8区明天0点的标准时间字符串,这个时间居然是8点钟!,也就是说,自动调整了时区!!!
	public String stdTimeStringForTomorrowZero() {
		Date d_now = new Date();
		long l = 24 * 60 * 60 * 1000;
		long l_tomorrowZero = d_now.getTime() - d_now.getTime() % l + l - 8 * 60 * 60 * 1000;
		Date d_tomorrowZero = new Date(l_tomorrowZero);
		return mssdf.format(d_tomorrowZero);
	}

	public String timeStringForNow() {
		Date d_now = new Date();
		return mssdf.format(d_now);
	}

//	    public static String timeStringForNow() {
//	        Date d_now = new Date();
//	        return mssdf.format(d_now);
//	    }

	public String stdTimeStringInmmssForMiniSeconds(int miniSeconds) {
		int seconds = miniSeconds / 1000;
		return stdTimeStringInmmssForSeconds(seconds);
	}

	public String stdTimeStringInmmssForSeconds(int seconds) {
		int min = seconds / 60;
		int sec = seconds - min * 60;
		String result = String.format("%02d:%02d", min, sec);
		return result;
	}

	// 当前时间之后指定秒数
	public String stdTimeStringAfterNow(long msExpiretime) {
		Date d_now = new Date();
		long l_targetTime = d_now.getTime() + msExpiretime;
		//系统的生成参数单位是毫秒.
		Date d_targetTime = new Date(l_targetTime);
		return mssdf.format(d_targetTime);
	}
}
